// 支付策略模式
const paymentStrategies = {
  wechat: (orderInfo) => {
    return new Promise((resolve, reject) => {
      uni.requestPayment({
        provider: 'wxpay',
        ...orderInfo,
        success: resolve,
        fail: reject
      })
    })
  },
  
  alipay: (orderInfo) => {
    return new Promise((resolve, reject) => {
      uni.requestPayment({
        provider: 'alipay',
        ...orderInfo,
        success: resolve,
        fail: reject
      })
    })
  },
  
  unionpay: (orderInfo) => {
    return new Promise((resolve, reject) => {
      uni.requestPayment({
        provider: 'unionpay',
        ...orderInfo,
        success: resolve,
        fail: reject
      })
    })
  }
}

// 支付控制器
export const paymentController = {
  pay(type, orderInfo) {
    const strategy = paymentStrategies[type]
    if (strategy) {
      return strategy(orderInfo)
    }
    throw new Error(`不支持的支付方式: ${type}`)
  },
  
  // 获取可用支付方式
  getAvailableMethods() {
    return Object.keys(paymentStrategies)
  }
}